//
//  DemoResizeViewViewController.m
//  DemoResizeView
//
//  Created by duc nguyen van on 8/17/11.
//  Copyright 2011 STU. All rights reserved.
//

#import "DemoResizeViewViewController.h"

@implementation DemoResizeViewViewController

#pragma mark -
#pragma mark delegate RisizeView

-(void)checkTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	if(ChangView.hidden == YES){
		ChangView.hidden = NO;
	}
}

#pragma mark -
#pragma mark delegate RisizeViewChange

-(void)scaleViewWithVex:(int)index andVex:(CGPoint)vex{
	switch (index) {
		case 1:
			Rview.frame = CGRectMake(Rview.frame.origin.x + vex.x, Rview.frame.origin.y + vex.y, Rview.frame.size.width - vex.x, Rview.frame.size.height - vex.y);	
			break;
			
		case 2:			
			Rview.frame = CGRectMake(Rview.frame.origin.x, Rview.frame.origin.y + vex.y, Rview.frame.size.width, Rview.frame.size.height - vex.y);	
			break;

		case 3:
			Rview.frame = CGRectMake(Rview.frame.origin.x , Rview.frame.origin.y + vex.y, Rview.frame.size.width + vex.x, Rview.frame.size.height - vex.y);	
			break;
			
		case 4:
			Rview.frame = CGRectMake(Rview.frame.origin.x , Rview.frame.origin.y, Rview.frame.size.width + vex.x, Rview.frame.size.height);	
			break;
			
		case 5:
			Rview.frame = CGRectMake(Rview.frame.origin.x , Rview.frame.origin.y, Rview.frame.size.width + vex.x, Rview.frame.size.height + vex.y);	
			break;
			
		case 6:
			Rview.frame = CGRectMake(Rview.frame.origin.x , Rview.frame.origin.y, Rview.frame.size.width, Rview.frame.size.height + vex.y);	
			break;

		case 7:
			Rview.frame = CGRectMake(Rview.frame.origin.x + vex.x, Rview.frame.origin.y, Rview.frame.size.width - vex.x, Rview.frame.size.height + vex.y);	
			break;
			
		case 8:
			Rview.frame = CGRectMake(Rview.frame.origin.x + vex.x, Rview.frame.origin.y, Rview.frame.size.width - vex.x, Rview.frame.size.height);	
			break;	
		
		default:
			break;
	}
	
}

-(void)checkTouchesBegan:(UITapGestureRecognizer *)tap{
	
}

-(void)checkTouchesMoved:(UIPanGestureRecognizer *)pan andVex:(CGPoint)vex{
	CGPoint cen = Rview.center;
	cen.x += vex.x;
	cen.y += vex.y;
	Rview.center = cen;
}

-(void)checkTouchesEnded:(UITapGestureRecognizer *)tap{
	
}

#pragma mark -

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	//create view
	Rview = [[ResizeView alloc] initWithFrame:CGRectMake(350, 350, 200, 200)];
	Rview.backgroundColor = [UIColor yellowColor];
	Rview.delegate = self;
	[self.view addSubview:Rview];
	
	//create change view
	float percent = 30;
	ChangView = [[ResizeViewChange alloc] initWithFrame:CGRectMake(0, 0, 
																   Rview.frame.size.width + ( Rview.frame.size.width * percent / 100), 
																   Rview.frame.size.height + ( Rview.frame.size.height * percent / 100))];
	ChangView.center = Rview.center;
	ChangView.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0];
	ChangView.delegate = self;
	ChangView.hidden = YES;
	[self.view addSubview:ChangView];

}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[Rview release];
	[ChangView release];
    [super dealloc];
}

@end
